﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using DotNet.Business;
using DotNet.Model;
using DotNet.Common;
using System.Text;
using System.Collections.Generic;
public partial class Admin_EditUser : System.Web.UI.Page
{
    adminBll aBll = new adminBll();
    admin adminModel = new admin();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {           
            if (Request.QueryString["state"]!=null)
            {
                string state = Request.QueryString["state"].ToString();
                int uid = Convert.ToInt32(Request.QueryString["uid"].ToString());
                switch (state.Trim())
                {
                    case "edit":

                        loadUser(uid);
                        break;
                    case "update":
                        updateUser(uid);
                        break;
                    default:
                        break;
                }
            }
            
           
            
        }
    }
    #region 给html控件赋值---郑同飞
    /// <summary>
    /// 给html控件赋值---郑同飞
    /// </summary>
    /// <param name="uid"></param>
    public void loadUser(int uid)
    {
        this.uid_hid.Value = uid.ToString();
        adminModel = aBll.GetModel(uid);
        this.adminUser.Value = adminModel.adminUser;
        this.pwd_hid.Value = adminModel.adminPwd;
        this.adminName.Value = adminModel.adminName;
        this.adminEmail.Value = adminModel.adminEmail;
        this.Tel.Value = adminModel.adminTel;
        this.qq.Value = adminModel.adminQQ;
        this.adminMark.Value = adminModel.adminMark;
        this.sex.Value = adminModel.adminSex;
    }
    #endregion

    #region 跟新用户---郑同飞
    public void updateUser(int uid) 
    {
        adminModel.adminId = uid;
        if (Request.Form["adminuser"].ToString().Trim() == "")
        {
            Response.Write("必填信息不完整或则有人已经注册了该账户");
            Response.End();
        }
        adminModel.adminUser = Request.Form["adminuser"].ToString();
        if (Request.Form["adminpwd"].ToString()!= "")
        {
            adminModel.adminPwd =CommUtil.DotEnCrypt(Request.Form["adminpwd"].ToString(),24);
        }
        else
        {
            adminModel.adminPwd =Request.QueryString["pwd"].ToString() ;
        }
        adminModel.adminName = Request.Form["adminname"].ToString();
        adminModel.adminEmail = Request.Form["adminemail"].ToString();
        adminModel.adminTel = Request.Form["tel"].ToString();
        adminModel.adminQQ = Request.Form["qq"].ToString();
        adminModel.adminMark = Request.Form["adminmark"].ToString();
        adminModel.adminDate =Convert.ToDateTime(DateTime.Now.ToShortDateString());
        adminModel.adminSex = Request.Form["sex"].ToString();
        if (aBll.Update(adminModel))
        {
            Response.Write("1");
            Response.End();
            
        }

    }
    #endregion 
    protected void adminPwd_ServerChange(object sender, EventArgs e)
    {

    }
}
